package com.song.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.song.dao.StudentDao;
import com.song.po.Student;
import com.song.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@Service
public class StudentServiceImpl implements StudentService {
   @Autowired
   private StudentDao studentDao;

   @Override
   public List<Student> getAllStudentList() {
      List<Student> list = studentDao.getALLStudentList();
      return list;
   }

   @Override
   public List<Student> getStudentByWrapper(Student student) {
      QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
      if(student.getStudentName() != null && !(student.getStudentName() .equals(""))){
         queryWrapper.like("student_name",student.getStudentName());
      }
      if(student.getNetClass().getNetClassName() != null && !(student.getNetClass().getNetClassName() .equals(""))){
         queryWrapper.like("netClass_name",student.getNetClass().getNetClassName());
      }
      if(student.getTelephone() != null && !(student.getTelephone() .equals(""))){
         queryWrapper.like("telephone",student.getTelephone());
      }
      if(student.getRoom().getRoomAddress() != null && !(student.getRoom().getRoomAddress() .equals(""))){
         queryWrapper.like("room_address",student.getRoom().getRoomAddress());
      }
      List<Student> list = studentDao.getStudentsByWrapper(queryWrapper);
      return list;
   }

   private void count(){
      System.out.println("测试");
      List<Integer> list = new ArrayList();
      for (int i = 0;i<10;i++) {
         list.add(i);
         System.out.println(i);
      }
      List<Integer> collect = list.stream().map(Integer::intValue).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
      collect.forEach(System.out::println);
   }

   /**
    * zqs
    */
   public void test(){
      System.out.println("测试哈哈哈");
   }
}
